import { Router } from 'express';
import { logger } from '../utils/logger';

// 客户端路由导入
import clientAuthRoutes from './client/auth';
import clientUserRoutes from './client/users';

// 管理后台路由导入
import adminAuthRoutes from './admin/auth';
import adminUserRoutes from './admin/users';
import adminRoleRoutes from './admin/roles';
import adminPermissionRoutes from './admin/permissions';
import adminSystemRoutes from './admin/system';
import adminLogRoutes from './admin/logs';

const router = Router();

// 路由配置函数
export function configureRoutes(): Router {
  logger.info('🔧 配置API路由...');

  // 客户端API路由 (Client API)
  logger.info('📱 注册客户端API路由: /api/client/*');
  router.use('/api/client/auth', clientAuthRoutes);
  router.use('/api/client/users', clientUserRoutes);

  // 管理后台API路由 (Admin API)
  logger.info('⚙️ 注册管理后台API路由: /api/admin/*');
  router.use('/api/admin/auth', adminAuthRoutes);
  router.use('/api/admin/users', adminUserRoutes);
  router.use('/api/admin/roles', adminRoleRoutes);
  router.use('/api/admin/permissions', adminPermissionRoutes);
  router.use('/api/admin/system', adminSystemRoutes);
  router.use('/api/admin/logs', adminLogRoutes);

  // 兼容性路由 (保持向后兼容)
  logger.info('🔄 注册兼容性路由: /api/*');
  router.use('/api/auth', clientAuthRoutes);
  router.use('/api/users', clientUserRoutes);

  logger.info('✅ API路由配置完成');
  
  return router;
}

// 获取路由信息
export function getRouteInfo(): { client: string[], admin: string[], compatibility: string[] } {
  return {
    client: [
      '/api/client/auth/*',
      '/api/client/users/*'
    ],
    admin: [
      '/api/admin/auth/*',
      '/api/admin/users/*',
      '/api/admin/roles/*',
      '/api/admin/permissions/*',
      '/api/admin/system/*',
      '/api/admin/logs/*'
    ],
    compatibility: [
      '/api/auth/*',
      '/api/users/*'
    ]
  };
}

export default router;